<template>
  <section class="group-list">
    <Tabs value="name1">
      <TabPane label="产品" name="name2"><div class="inner">
        <div class="draw-back">
          <Form :model="formItem" label-position="right" :label-width="80">
            <FormItem label="商品名称：">
              <Input v-model="formItem.name"></Input>
            </FormItem>
            <FormItem label="商品类别：">
              <Select v-model="formItem.pro" style="width:290px" @on-change="selpro">
                <Option v-for="item in proList" :value="item.id" :key="item.id" >{{ item.name }}</Option>
              </Select>
            </FormItem>
            <FormItem label="品牌：">
              <Input v-model="formItem.brand"></Input>
            </FormItem>
            <FormItem label="商品数量：">
              <Input v-model="formItem.num"></Input>
            </FormItem>
            <FormItem label="采购地：">
              <RadioGroup v-model="formItem.radio">
                <Radio label="0">国内</Radio>
                <Radio label="1">海外及港澳台</Radio>
              </RadioGroup>
            </FormItem>
            <FormItem label="商家编码：">
              <Input v-model="formItem.code"></Input>
            </FormItem>
            <FormItem label="商家地址：">
              <Input v-model="formItem.address"></Input>
            </FormItem>
            <FormItem label="生产厂家：">
              <Input v-model="formItem.factory"></Input>
            </FormItem>
            <FormItem label="现价：">
              <Input v-model="formItem.nowprice"></Input>
            </FormItem>
            <FormItem label="折扣：">
              <Input v-model="formItem.sale"></Input>
            </FormItem>
            <FormItem label="商品卖点：">
              <Input v-model="formItem.notice" type="textarea" :rows="4" placeholder="请输入..." />
            </FormItem>
            <FormItem label="上传图片：">
              <el-upload
                      :action="UploadUrl()"
                      list-type="picture-card"
                      :on-success="handleRemove"
                      :file-list="fileList"
                      :class="{disabled:uploadDisabled}"
                      :limit="4">
                <i class="el-icon-plus"></i>
              </el-upload>
            </FormItem>
          </Form>
        </div>
        <div style="padding-left: 70px;">
          <Button type="primary" size="large" style="width: 100px" @click="subimt">发布</Button>
        </div>
      </div></TabPane>
    </Tabs>

  </section>
</template>

<script>

export default {
  name: 'ProjectList',
  components: {

  },
   data () {
      return {
          single:false,
          formItem: {},
          proList: [],
          cityList: [],
          disList: [],
          model1: '',
          pid:0,
          city:1,
          dis:2,
          list: [''],
          image:'',
          images:[],
          id:'',
          fileList:[],
          uploadDisabled:false
      }
   },
    created () {
        this.getinfo()
    },
    computed: {

    },
    methods: {
        UploadUrl(){
            return  this.$Url+'/api/common/upload';
        },
        handleRemove (res) {
            console.log(res)
            this.images.push(res.data.url)
            console.log(this.images)
            if(this.images.length == 4){
                this.uploadDisabled = true
            }
        },
        getinfo () {
            this.id = this.$route.query.id
            let _this =this
            this.$post('/api/goods/getGoodInfo',
                {
                    good_id:_this.id
                }, function (res) {
                    _this.formItem = res.data
                    res.data.images.forEach(function (i) {
                        let obj ={}
                        obj.url =_this.$Url+i
                        _this.fileList.push(obj)

                    })
                    if(_this.fileList.length>_this.fileList.length+1){
                        _this.uploadDisabled = true
                    }
                    _this.adrass(_this.formItem.gfgroup_id)
                }, function (errcode, errmsg,err) {
                    console.log(errmsg)
                })
        },

        add() {
            this.list.push('')
        },
        subimt () {
            this.formItem.ismoney = this.single ? 1:2;
            console.log(this.list);
            // return false;
            let _this =this
            this.$post('/api/project/add_project',
                {
                    token:_this.$token,
                    group_id:_this.pid,
                    name:_this.formItem.name,
                    brand:_this.formItem.brand,
                    num:_this.formItem.num,
                    place:_this.formItem.radio,
                    code:_this.formItem.code,
                    address:_this.formItem.address,
                    factory:_this.formItem.factory,
                    nowprice:_this.formItem.nowprice,
                    sale:_this.formItem.sale,
                    notice:_this.formItem.notice,
                    images:_this.img,
                    good_id:_this.id
                }, function (res) {
                  console.log(res)

                    _this.$message({
                        message: res.msg,
                        type: 'success'
                    });
                }, function (errcode, errmsg,err) {
                    // console.log(err)
                    console.log(errmsg)

                })
        },
        adrass (id) {
            let _this =this
            this.$post('/api/project/project_type',
                {
                    pid:0,
                }, function (res) {
                    _this.proList = res.data
                    _this.proList.forEach(function (i) {
                        if(id == i.id){
                            _this.formItem.pro = id;
                            _this.diss()
                        }
                    })

                }, function (errcode, errmsg,err) {
                    console.log(err)
                    console.log(errmsg)
                })
        },
        diss () {
            let _this =this
            this.$post('/api/project/project_type',
                {
                    pid:_this.formItem.pro,
                }, function (res) {
                    _this.disList = res.data
                    _this.disList.forEach(function (i) {
                        if(_this.formItem.fgroup_id == i.id){
                            _this.formItem.city = i.id;
                           _this.citys()

                        }
                    })
                    console.log(res.data)
                }, function (errcode, errmsg,err) {
                    console.log(err)
                    console.log(errmsg)
                })
        },
        citys () {
            let _this =this
            this.$post('/api/project/project_type',
                {
                    pid:_this.city,
                }, function (res) {
                    _this.cityList = res.data
                    _this.cityList.forEach(function (i) {
                        if(_this.formItem.group_id == i.id){
                            _this.formItem.name = i.id;
                        }
                    })
                }, function (errcode, errmsg,err) {
                    console.log(err)
                    console.log(errmsg)
                })
        },
        selpro (value) {
            this.city = value
            console.log(value)
            this.citys()
        },
        selcity (value) {
            console.log(value)
            this.dis = value
            this.diss()
        }
    }
}

</script>

<style lang="less" scoped>
  @import "../../../style/style.less";
  .ivu-input-wrapper[data-v-0cf3f6cd]{
    width: 287px;
    margin: 6px 0;
  }
  .ico-add{
    float: right;
    margin: 0px -40px 0 0px;
    font-size: 25px;
  }
  .group-list {
    border: 1px solid @border-color;
    padding: 15px;
    >:first-child{
      color: #333333;
      font-size: 18px;
      padding-bottom: 15px;
      span{
        font-size: 18px;
        color: @theme-color-dark;
        margin-left: 20px;
      }
    }
    .inner {
      padding-top: 15px;
    }
    .draw-back {
      width: 535px;
    }
    .tips {
      color: #333;
      font-size: 16px;
      font-weight: bold;
    }
    .selected-box {
      padding: 10px 0;
      margin-bottom: 20px;
      .item {
        color: @theme-color-dark;
        background-color: @theme-color-light;
        font-size: 14px;
        height: 28px;
        line-height: 28px;
        display: inline-block;
        margin: 14px 18px 0 0;
        border-radius: 4px;
        padding: 0 10px;
        cursor: pointer;
      }
      .active {
        background-color: @theme-color-dark;
        color: #fff;
      }
    }
  }
</style>
